$(document).ready(function() {
	$('#example').dataTable();
	$('#rowSelectAll').on('change', function() {
		$('.myswitch').each(function() {

			if ($(this).hasClass('switch-on')) {
				$(this).bootstrapSwitch('setState', false);
				$(this).removeClass('switch-on');
			} else {

				$(this).bootstrapSwitch('setState', true);
				$(this).addClass('switch-on');
			}
		});
	});
});
$(document).ready(function() {
	$('.combobox').combobox();
});

function searchTongle() {
	$("#searchTongle").slideToggle(500);
	if ($('#txtSearch').is(":visible")) {
		$('#txtSearch').hide();
		$('#btnSearch').hide();
	} else {
		$('#txtSearch').show();
		$('#btnSearch').show();
	}
}
function logoutTongles(){
	//$("#logout_tongle").slideToggle(500);
	$("#logout_tongle").toggle();
	//$("#test_tongle").show()
	
	}
$( "#logout_tongle11").click(function() {
	  //$( "#logout_tongle" ).toggle("fold",1);
	  $('#logout_tongle').animate({
          height: 'toggle'
          }, 300
     );
	});
/**
 * function search list customer by id
 */

function prepareHtml(response, role) {
	var content = "";
	$
			.each(
					response,
					function(i, post) {
						content += "<tr role='row' class='odd'>";
						content += "<td class='sorting_1'>";
						content += post.accountNumber;
						content += "</td>";

						content += "<td>";
						content += post.identityCard;
						content += "</td>";

						content += "<td>";
						content += post.firstName;
						content += "</td>";

						content += "<td>";
						content += post.lastName;
						content += "</td>";

						content += "<td>";
						content += post.phone1;
						content += "</td>";

						content += "<td>";
						content += post.email1;
						content += "</td>";

						content += "<td style=\"text-align:center\">";
						content += post.state;
						content += "</td>";

						if (role == "admin") {
							content += "<td style=\"text-align:center\"><button type=\"button\"";
							content += "onclick=\"getAccountDetail("
									+ post.accountId + ")\"";
							content += "class=\"btn btn-default\" data-toggle=\"modal\"";
							content += "data-target=\"#md_transdetail\"";
							content += "value=\"\">Detail</button></td>";
						}

						content += "<td style=\"text-align:center\"><button type=\"button\" class=\"btn btn-default\"";
						content += "onclick=\"getAccountEdit(" + post.accountId
								+ ")\"";
						content += "data-toggle=\"modal\" data-target=\"#md_transdetail2\">Edit</button></td>";

						content += "</tr>";
					});
	return content;
}

function searchSimple() {
	var txtSearch = $('#txtSearch').val();
	$.ajax({
		type : "POST",
		url : "json/accountinfo/searchAccountInfo",
		data : {
			"txtSearch" : txtSearch
		},
		dataType : "json",
		success : function(response) {
			$('#tbodyAccount').html(prepareHtml(response, "admin"));
		},
		error : function(err) {
			alert("Error: " + err);
		}
	});
}

function searchAdvance() {
	$.ajax({
		type : "POST",
		url : "json/accountinfo/searchAdvance",
		data : {
			"accountNumber" : $("#accountNumber").val(),
			"identifyCard" : $("#identifyCard").val(),
			"firstName" : $("#firstName").val(),
			"lastName" : $("#lastName").val(),
			"phone" : $("#phone").val(),
			"stateId" : $("#stateId").val()
		},
		dataType : 'json',
		success : function(response) {
			$('#tbodyAccount').html(prepareHtml(response, "admin"));
		},
		error : function(e) {
			alert('Error ' + e);
		}

	});
}